package charazay.tool.ihm.overview;

import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Color;
import javax.swing.SwingConstants;

import charazay.tool.cobjects.Player;
import charazay.tool.misc.Country;

public class PlayerCardPanel extends JPanel {

	private static String[] COLOR = {
		"#FFFF88","#FFFF77","#FFFF66","#FFFF55","#FFFF44","#FFFF33","#FFFF22","#FFFF11","#FFFF00","#FFCC00",
        "#FF9900","#FF8800","#FF7700","#FF6600","#FF5500","#FF4400","#FF3300","#FF2200","#FF1100","#FF0000",
        "#CC0000","#990000","#880000","#770000","#660000","#550000","#440000","#330000","#220000","#110000"};
	
	/**
	 * Create the panel.
	 */
	public PlayerCardPanel(Player playerObject) {
		
		Vector player = playerObject.asVector();
		
		setBackground(new Color(128, 128, 128));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{50, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		
		//player name
		JLabel lblFirstName = new JLabel("Name : "+(String)player.get(0)+" "+(String)player.get(1));
		GridBagConstraints gbc_lblFirstName = new GridBagConstraints();
		gbc_lblFirstName.anchor = GridBagConstraints.WEST;
		gbc_lblFirstName.insets = new Insets(0, 0, 5, 5);
		gbc_lblFirstName.gridx = 1;
		gbc_lblFirstName.gridy = 1;
		add(lblFirstName, gbc_lblFirstName);
		
		//defence
		JLabel lblDefence = new JLabel("Defence");
		GridBagConstraints gbc_lblDefence = new GridBagConstraints();
		gbc_lblDefence.anchor = GridBagConstraints.WEST;
		gbc_lblDefence.insets = new Insets(0, 0, 5, 5);
		gbc_lblDefence.gridx = 5;
		gbc_lblDefence.gridy = 1;
		add(lblDefence, gbc_lblDefence);
		
		JLabel label_6 = new JLabel(((Integer)player.get(7)).toString());
		label_6.setForeground(getColor((Integer)player.get(7)));
		GridBagConstraints gbc_label_6 = new GridBagConstraints();
		gbc_label_6.anchor = GridBagConstraints.WEST;
		gbc_label_6.insets = new Insets(0, 0, 5, 5);
		gbc_label_6.gridx = 7;
		gbc_label_6.gridy = 1;
		add(label_6, gbc_label_6);
		
		//carac LF
		JLabel lblFreeThrow = new JLabel("Free throw");
		GridBagConstraints gbc_lblFreeThrow = new GridBagConstraints();
		gbc_lblFreeThrow.anchor = GridBagConstraints.WEST;
		gbc_lblFreeThrow.insets = new Insets(0, 0, 5, 5);
		gbc_lblFreeThrow.gridx = 9;
		gbc_lblFreeThrow.gridy = 1;
		add(lblFreeThrow, gbc_lblFreeThrow);
		
		JLabel label_11 = new JLabel(((Integer)player.get(8)).toString());
		label_11.setForeground(getColor((Integer)player.get(8)));
		GridBagConstraints gbc_label_11 = new GridBagConstraints();
		gbc_label_11.anchor = GridBagConstraints.WEST;
		gbc_label_11.insets = new Insets(0, 0, 5, 5);
		gbc_label_11.gridx = 11;
		gbc_label_11.gridy = 1;
		add(label_11, gbc_label_11);
		
		String country_label = Country.countries.get(new Integer(playerObject.countryid));
		JLabel lblNewLabel = new JLabel(new ImageIcon(PlayerCardPanel.class.getResource("/media/flags/"+country_label+"-Flag-24.png")));
		lblNewLabel.setText(country_label);
		lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.anchor = GridBagConstraints.WEST;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 1;
		gbc_lblNewLabel.gridy = 2;
		add(lblNewLabel, gbc_lblNewLabel);
		
		//carac 2pts 
		JLabel lblPts = new JLabel("2 pts");
		GridBagConstraints gbc_lblPts = new GridBagConstraints();
		gbc_lblPts.anchor = GridBagConstraints.WEST;
		gbc_lblPts.insets = new Insets(0, 0, 5, 5);
		gbc_lblPts.gridx = 5;
		gbc_lblPts.gridy = 2;
		add(lblPts, gbc_lblPts);
		
		JLabel label_7 = new JLabel(((Integer)player.get(9)).toString());
		label_7.setForeground(getColor((Integer)player.get(9)));
		GridBagConstraints gbc_label_7 = new GridBagConstraints();
		gbc_label_7.anchor = GridBagConstraints.WEST;
		gbc_label_7.insets = new Insets(0, 0, 5, 5);
		gbc_label_7.gridx = 7;
		gbc_label_7.gridy = 2;
		add(label_7, gbc_label_7);
		
		//carac 3pts
		JLabel lblPts_1 = new JLabel("3 pts");
		GridBagConstraints gbc_lblPts_1 = new GridBagConstraints();
		gbc_lblPts_1.anchor = GridBagConstraints.WEST;
		gbc_lblPts_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblPts_1.gridx = 9;
		gbc_lblPts_1.gridy = 2;
		add(lblPts_1, gbc_lblPts_1);
		
		JLabel label_12 = new JLabel(((Integer)player.get(10)).toString());
		label_12.setForeground(getColor((Integer)player.get(10)));
		GridBagConstraints gbc_label_12 = new GridBagConstraints();
		gbc_label_12.anchor = GridBagConstraints.WEST;
		gbc_label_12.insets = new Insets(0, 0, 5, 5);
		gbc_label_12.gridx = 11;
		gbc_label_12.gridy = 2;
		add(label_12, gbc_label_12);
		
		//Age
		JLabel lblAge = new JLabel("Age : "+((Integer)player.get(2)).toString());
		GridBagConstraints gbc_lblAge = new GridBagConstraints();
		gbc_lblAge.anchor = GridBagConstraints.WEST;
		gbc_lblAge.insets = new Insets(0, 0, 5, 5);
		gbc_lblAge.gridx = 1;
		gbc_lblAge.gridy = 3;
		add(lblAge, gbc_lblAge);

		//Dribbling
		JLabel lblDribbling = new JLabel("Dribbling");
		GridBagConstraints gbc_lblDribbling = new GridBagConstraints();
		gbc_lblDribbling.anchor = GridBagConstraints.WEST;
		gbc_lblDribbling.insets = new Insets(0, 0, 5, 5);
		gbc_lblDribbling.gridx = 5;
		gbc_lblDribbling.gridy = 3;
		add(lblDribbling, gbc_lblDribbling);
		
		JLabel label_8 = new JLabel(((Integer)player.get(11)).toString());
		label_8.setForeground(getColor((Integer)player.get(11)));
		GridBagConstraints gbc_label_8 = new GridBagConstraints();
		gbc_label_8.anchor = GridBagConstraints.WEST;
		gbc_label_8.insets = new Insets(0, 0, 5, 5);
		gbc_label_8.gridx = 7;
		gbc_label_8.gridy = 3;
		add(label_8, gbc_label_8);
		
		//Passing
		JLabel lblPassing = new JLabel("Passing");
		GridBagConstraints gbc_lblPassing = new GridBagConstraints();
		gbc_lblPassing.anchor = GridBagConstraints.WEST;
		gbc_lblPassing.insets = new Insets(0, 0, 5, 5);
		gbc_lblPassing.gridx = 9;
		gbc_lblPassing.gridy = 3;
		add(lblPassing, gbc_lblPassing);
		
		JLabel label_13 = new JLabel(((Integer)player.get(12)).toString());
		label_13.setForeground(getColor((Integer)player.get(12)));
		GridBagConstraints gbc_label_13 = new GridBagConstraints();
		gbc_label_13.anchor = GridBagConstraints.WEST;
		gbc_label_13.insets = new Insets(0, 0, 5, 5);
		gbc_label_13.gridx = 11;
		gbc_label_13.gridy = 3;
		add(label_13, gbc_label_13);
		
		//Height
		JLabel lblHeight = new JLabel("Height : "+((Integer)player.get(5)).toString());
		GridBagConstraints gbc_lblHeight = new GridBagConstraints();
		gbc_lblHeight.anchor = GridBagConstraints.WEST;
		gbc_lblHeight.insets = new Insets(0, 0, 5, 5);
		gbc_lblHeight.gridx = 1;
		gbc_lblHeight.gridy = 4;
		add(lblHeight, gbc_lblHeight);
		
		//Speed
		JLabel lblSpeed = new JLabel("Speed");
		GridBagConstraints gbc_lblSpeed = new GridBagConstraints();
		gbc_lblSpeed.anchor = GridBagConstraints.WEST;
		gbc_lblSpeed.insets = new Insets(0, 0, 5, 5);
		gbc_lblSpeed.gridx = 5;
		gbc_lblSpeed.gridy = 4;
		add(lblSpeed, gbc_lblSpeed);
		
		JLabel label_9 = new JLabel(((Integer)player.get(13)).toString());
		label_9.setForeground(getColor((Integer)player.get(13)));
		GridBagConstraints gbc_label_9 = new GridBagConstraints();
		gbc_label_9.anchor = GridBagConstraints.WEST;
		gbc_label_9.insets = new Insets(0, 0, 5, 5);
		gbc_label_9.gridx = 7;
		gbc_label_9.gridy = 4;
		add(label_9, gbc_label_9);
		
		//Footwork
		JLabel lblFootwork = new JLabel("Footwork");
		GridBagConstraints gbc_lblFootwork = new GridBagConstraints();
		gbc_lblFootwork.anchor = GridBagConstraints.WEST;
		gbc_lblFootwork.insets = new Insets(0, 0, 5, 5);
		gbc_lblFootwork.gridx = 9;
		gbc_lblFootwork.gridy = 4;
		add(lblFootwork, gbc_lblFootwork);
		
		JLabel label_14 = new JLabel(((Integer)player.get(14)).toString());
		label_14.setForeground(getColor((Integer)player.get(14)));
		GridBagConstraints gbc_label_14 = new GridBagConstraints();
		gbc_label_14.anchor = GridBagConstraints.WEST;
		gbc_label_14.insets = new Insets(0, 0, 5, 5);
		gbc_label_14.gridx = 11;
		gbc_label_14.gridy = 4;
		add(label_14, gbc_label_14);
		//Weight
		JLabel lblWeight = new JLabel("Weight : "+((Float)player.get(6)).toString());
		GridBagConstraints gbc_lblWeight = new GridBagConstraints();
		gbc_lblWeight.anchor = GridBagConstraints.WEST;
		gbc_lblWeight.insets = new Insets(0, 0, 5, 5);
		gbc_lblWeight.gridx = 1;
		gbc_lblWeight.gridy = 5;
		add(lblWeight, gbc_lblWeight);
		
		//Experience and Rebond
		JLabel lblRebond = new JLabel("Rebond");
		GridBagConstraints gbc_lblRebond = new GridBagConstraints();
		gbc_lblRebond.anchor = GridBagConstraints.WEST;
		gbc_lblRebond.insets = new Insets(0, 0, 5, 5);
		gbc_lblRebond.gridx = 5;
		gbc_lblRebond.gridy = 5;
		add(lblRebond, gbc_lblRebond);
	
		JLabel label_10 = new JLabel(((Integer)player.get(15)).toString());
		label_10.setForeground(getColor((Integer)player.get(15)));
		GridBagConstraints gbc_label_10 = new GridBagConstraints();
		gbc_label_10.anchor = GridBagConstraints.WEST;
		gbc_label_10.insets = new Insets(0, 0, 5, 5);
		gbc_label_10.gridx = 7;
		gbc_label_10.gridy = 5;
		add(label_10, gbc_label_10);
		
		JLabel lblExperience = new JLabel("Experience");
		GridBagConstraints gbc_lblExperience = new GridBagConstraints();
		gbc_lblExperience.anchor = GridBagConstraints.WEST;
		gbc_lblExperience.insets = new Insets(0, 0, 5, 5);
		gbc_lblExperience.gridx = 9;
		gbc_lblExperience.gridy = 5;
		add(lblExperience, gbc_lblExperience);

		JLabel label_15 = new JLabel(((Integer)player.get(16)).toString());
		label_15.setForeground(getColor((Integer)player.get(16)));
		GridBagConstraints gbc_label_15 = new GridBagConstraints();
		gbc_label_15.anchor = GridBagConstraints.WEST;
		gbc_label_15.insets = new Insets(0, 0, 5, 5);
		gbc_label_15.gridx = 11;
		gbc_label_15.gridy = 5;
		add(label_15, gbc_label_15);
		
		//Skill index
		JLabel lblSkillIndex = new JLabel("Skill Index : "+((Integer)player.get(3)).toString());
		GridBagConstraints gbc_lblSkillIndex = new GridBagConstraints();
		gbc_lblSkillIndex.anchor = GridBagConstraints.WEST;
		gbc_lblSkillIndex.insets = new Insets(0, 0, 5, 5);
		gbc_lblSkillIndex.gridx = 1;
		gbc_lblSkillIndex.gridy = 7;
		add(lblSkillIndex, gbc_lblSkillIndex);
		
		//Salary
		JLabel lblSalary = new JLabel("Salary : "+((Integer)player.get(4)).toString());
		GridBagConstraints gbc_lblSalary = new GridBagConstraints();
		gbc_lblSalary.anchor = GridBagConstraints.WEST;
		gbc_lblSalary.insets = new Insets(0, 0, 5, 5);
		gbc_lblSalary.gridx = 1;
		gbc_lblSalary.gridy = 8;
		add(lblSalary, gbc_lblSalary);

	}
	
	private Color getColor(Integer index) {
		return Color.decode(COLOR[index.intValue()-1]);
	}

}
